package com.industrial.operation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.operation.domain.OperationFocusProduct;
import com.industrial.operation.service.IOperationFocusProductService;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.page.TableDataInfo;

/**
 * 重点产品调度Controller
 * 
 * @author ZhouS
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/focusProduct")
public class OperationFocusProductController extends BaseController
{
    @Autowired
    private IOperationFocusProductService operationFocusProductService;

    /**
     * 查询重点产品调度列表
     */
    @RequiresPermissions("operation:focusProduct:list")
    @GetMapping("/list")
    public TableDataInfo list(OperationFocusProduct operationFocusProduct)
    {
        startPage();
        if(StringUtils.isNotBlank(operationFocusProduct.getYearMonth())){
            String yearMohth=operationFocusProduct.getYearMonth()+"-01";
            operationFocusProduct.setYearMonth(yearMohth);
        }
        List<OperationFocusProduct> list = operationFocusProductService.selectOperationFocusProductList(operationFocusProduct);
        return getDataTable(list);
    }

    /**
     * 导出重点产品调度列表
     */
    @RequiresPermissions("operation:focusProduct:export")
    @Log(title = "重点产品调度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperationFocusProduct operationFocusProduct)
    {
        List<OperationFocusProduct> list = operationFocusProductService.selectOperationFocusProductList(operationFocusProduct);
        ExcelUtil<OperationFocusProduct> util = new ExcelUtil<OperationFocusProduct>(OperationFocusProduct.class);
        util.exportExcel(response, list, "重点产品调度数据");
    }

    /**
     * 获取重点产品调度详细信息
     */
    @RequiresPermissions("operation:focusProduct:query")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(operationFocusProductService.selectOperationFocusProductByBaseId(baseId));
    }

    /**
     * 新增重点产品调度
     */
    @RequiresPermissions("operation:focusProduct:add")
    @Log(title = "重点产品调度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationFocusProduct operationFocusProduct)
    {
        return toAjax(operationFocusProductService.insertOperationFocusProduct(operationFocusProduct));
    }

    /**
     * 修改重点产品调度
     */
    @RequiresPermissions("operation:focusProduct:edit")
    @Log(title = "重点产品调度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperationFocusProduct operationFocusProduct)
    {
        return toAjax(operationFocusProductService.updateOperationFocusProduct(operationFocusProduct));
    }

    /**
     * 删除重点产品调度
     */
    @RequiresPermissions("operation:focusProduct:remove")
    @Log(title = "重点产品调度", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(operationFocusProductService.deleteOperationFocusProductByBaseIds(baseIds));
    }
}
